package com.ymatou.iapi.im.testcase;

import com.ymatou.iapi.im.parameter.ResetCommentCountBean;
import com.ymatou.iapi.im.parameter.SendCommentBean;
import com.ymatou.iapi.im.service.ResetCommentCountCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.ImCallService;
import com.ymttest.database.sqlwapper.ImDefaultWapper;
import org.junit.*;
import org.junit.experimental.categories.Category;

import java.io.IOException;
import java.util.Map;

/**
*重置评论未读数
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_ResetCommentCount{
	private static ResetCommentCountBean resetcommentcountBean;
	private static ResetCommentCountCall resetcommentcountCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("重置评论未读数");
	}

	@Before
	public void caseUp() {
		resetcommentcountBean=new ResetCommentCountBean();
		resetcommentcountCall=new ResetCommentCountCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(resetcommentcountCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ResetCommentCount_001() {
		Logger.start(true,"重置评论未读数");
		try {
			ImCallService imCallService = new ImCallService();
			SendCommentBean sendCommentBean = imCallService.initSendComment();
			imCallService.SendComment(sendCommentBean);
			Thread.sleep(1000);
			checkUnReadCount(sendCommentBean);
			sendCommentBean.setMessage("nihao xingqiliu1");
			checkUnReadCount(sendCommentBean);
			imCallService.SendComment(sendCommentBean);
			sendCommentBean.setMessage("nihao xingqiliu3");
			imCallService.SendComment(sendCommentBean);
			checkUnReadCount(sendCommentBean);
//			ImDefaultWapper im = new ImDefaultWapper();
//			Map map = im.selectComment(sendCommentBean.getObjId(),sendCommentBean.getToUserId()).get(0);
//			Logger.verifyEquals(1,Integer.parseInt(map.get("UnReadCount").toString()),"验证UnReadCount");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	public void checkUnReadCount(SendCommentBean sendCommentBean) throws IOException, InterruptedException {
		resetcommentcountBean.setCount(0);
		resetcommentcountBean.setObjId(sendCommentBean.getObjId());
		resetcommentcountBean.setObjType(sendCommentBean.getObjType());
		resetcommentcountBean.setSenderUserId(sendCommentBean.getSenderUserId());
		resetcommentcountBean.setToUserId(sendCommentBean.getToUserId());
		resetcommentcountCall.setData(resetcommentcountBean);
		resetcommentcountCall.callService();
		Logger.verifyEquals("200",resetcommentcountCall.getString("Status"),"验证Status");
		Thread.sleep(1000);
		ImDefaultWapper im = new ImDefaultWapper();
		Map map = im.selectComment(sendCommentBean.getObjId(),sendCommentBean.getToUserId()).get(0);
		Logger.verifyEquals(0,Integer.parseInt(map.get("UnReadCount").toString()),"验证UnReadCount");
	}
}